package com.yfjin.webrtc.ws;

import android.util.Log;

import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;

import java.net.URI;
import java.nio.ByteBuffer;

public class WsClient extends WebSocketClient {

    private static final String TAG = "123123";
    private String mUrl;
    private IWsClientCallback mCallback;

    public void setCallback(IWsClientCallback callback) {
        mCallback = callback;
    }

    public WsClient(String url, URI serverURI) {
        super(serverURI);
        this.mUrl = url;
    }

    public String getUrl() {
        return mUrl;
    }

    @Override
    public void onOpen(ServerHandshake serverHandshake) {
        mCallback.onConenct(this);
    }

    @Override
    public void onMessage(String s) {
    }

    @Override
    public void onMessage(ByteBuffer bytes) {

    }

    //        音视频的
    @Override
    public void onClose(int i, String s, boolean b) {
        Log.i(TAG, "onClose: ");
    }

    @Override
    public void onError(Exception e) {
        e.printStackTrace();
        Log.i(TAG, "onError: ");
        mCallback.onDisConnect(this);
    }


    public interface IWsClientCallback{
        void onConenct(WsClient ws);
        void onDisConnect(WsClient ws);
    }

}
